<%@ Page Language="VB" MasterPageFile="../PageTemplate.master" MaintainScrollPositionOnPostback="true"
    Title="Content Page 1" AutoEventWireup="false" CodeFile="AdminOptions.aspx.vb"
    Inherits="AdminOptions" %>

<asp:Content ID="Content2" ContentPlaceHolderID="HeaderContent" runat="Server">
    Client clicks database
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="dividing_line" runat="server">
    <img src="../images/hline_red.gif" width="100%" />
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
    <div>
        <br />
        <asp:Panel ID="SearchPanel" runat="server" Visible="false">
            <table cellspacing="10px" style="background-color: #ff0000; color: Yellow; font-weight: bold;
                border-style: outset; border-color: #901111;">
                <tr>
                    <td align="left">
                        Client name:</td>
                    <td style="width: 158px">
                        <asp:TextBox ID="SearchField1" runat="server" /></td>
                </tr>
                <tr>
                    <td align="left">
                        User name:</td>
                    <td style="width: 158px">
                        <asp:TextBox ID="SearchField2" runat="server" /></td>
                </tr>
                <tr>
                    <td align="left">
                        Password:</td>
                    <td style="width: 158px">
                        <asp:TextBox ID="SearchField3" runat="server" /></td>
                </tr>
                <tr>
                    <td align="left">
                        Comments:</td>
                    <td style="width: 158px">
                        <asp:TextBox ID="SearchField4" runat="server" /></td>
                </tr>
            </table>
            <br />
            <asp:Button ID="Search_Button" runat="server" Text="Search" />&nbsp;<asp:Button ID="Cancel_Button"
                runat="server" Text="Cancel" />
        </asp:Panel>
        <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert"
            Visible="False" AutoGenerateRows="false" CellPadding="5">
            <Fields>
                <asp:TemplateField HeaderText="Client name">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox Width="160px" ID="Client_txtbox1" runat="server" />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Client_txtbox1"
                            ErrorMessage="You must enter a client name" ForeColor="yellowgreen" />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>

                <asp:TemplateField HeaderText="User name">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox Width="160px" ID="User_txtbox1" runat="server" />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="User_txtbox1"
                            ErrorMessage="You must enter a user name" ForeColor="yellowgreen" />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Password">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox Width="160px" ID="Password_txtbox1" runat="server" />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="Password_txtbox1"
                            ErrorMessage="You must enter a password" ForeColor="yellowgreen" />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>

                <asp:TemplateField HeaderText="E-mail">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox Width="160px" ID="email_txtbox1" runat="server" />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Client address">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox Width="160px" ID="ClientAddress_txtbox1" runat="server" />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="Comments">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox Width="160px" ID="comments_txtbox1" runat="server" Rows="5" TextMode="MultiLine"
                            Wrap="true" />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>
            </Fields>
            <FooterTemplate>
                <asp:Button runat="server" ID="myInsertButton" Text="Add client" CommandName="Insert" />
                <asp:Button runat="server" ID="myCancelButton" Text="Cancel" CommandName="Cancel"
                    CausesValidation="false" />
            </FooterTemplate>
        </asp:DetailsView>
        <table>
            <tr>
                <td style="width: 125px; text-align: left;">
                    <asp:Button ID="Button1" runat="server" Text="Add a user" Height="35px" Width="117px" /></td>
                <td style="width: 125px; text-align: center;">
                    <asp:Button ID="Button2" runat="server" Text="Search" Height="35px" Width="117px" /></td>
                <td style="width: 0px; text-align: right;">
                    <asp:Button ID="Button3" runat="server" Text="Remove search filters" Height="35px"
                        Width="148px" Visible="false" /></td>
            </tr>
        </table>
        <br />
           
        <asp:GridView ID="GridView1" runat="server" DataKeyNames="ID" AutoGenerateColumns="False"
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:CommandField HeaderText="Edit" EditText="Edit..." ShowEditButton="True" />
                
                <asp:HyperLinkField HeaderText="Purchases" Text="Purchases..."
                    DataNavigateUrlFormatString="Purchases.aspx?ID={0}" DataNavigateUrlFields="ID" />
                
                <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="true" Visible="false" />
                <asp:BoundField DataField="ClientName" HeaderText="Client" SortExpression="ClientName"  ItemStyle-Width="50px" />
                <asp:BoundField DataField="UserName" ControlStyle-Width="100px" HeaderText="User" SortExpression="UserName" />
                <asp:BoundField DataField="Password" ControlStyle-Width="100px" HeaderText="Password" SortExpression="Password" />
                
                <asp:TemplateField HeaderText="e-Mail" ItemStyle-Width="35px" >
                    <ItemTemplate>
                        <asp:Label runat="server" ID="eMail_label" Text='<%# email_splitter( eval("eMail") ) %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox runat="server" ID="multiline_eMail_textbox" Text='<%# Bind("eMail") %>'
                            TextMode="multiline" Rows="4" Wrap="true" />
                    </EditItemTemplate>
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="Client address" >
                    <ItemTemplate>
                        <asp:Label runat="server" ID="ClientAddress_label" Text='<%# left("" & eval("ClientAddress"), 30) %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox runat="server" ID="multiline_ClientAddress_textbox" Text='<%# Bind("ClientAddress") %>'
                            TextMode="multiline" Rows="4" Wrap="true" />
                    </EditItemTemplate>
                </asp:TemplateField>
                
                
                <asp:TemplateField HeaderText="Comments">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="comments_label" Text='<%# left("" & eval("Comments"),30) %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox runat="server" ID="multiline_comments_textbox" Text='<%# Bind("Comments") %>'
                            TextMode="multiline" Rows="4" Wrap="true" />
                    </EditItemTemplate>
                </asp:TemplateField>
                

                <asp:HyperLinkField SortExpression="Purchases_made" HeaderText="Purchases" 
                    DataTextField="Purchases_made" DataNavigateUrlFormatString="Purchases.aspx?ID={0}"
                    DataNavigateUrlFields="ID" />
                  
                  
<%--
                <asp:TemplateField HeaderText="Delete">
                 <ItemTemplate>
                   <asp:LinkButton ID="LinkButton1" 
                     CommandArgument='<%# Eval("ID") %>' 
                     CommandName="Delete" runat="server">
                     Delete...</asp:LinkButton>
                 </ItemTemplate>
               </asp:TemplateField>
--%>
                   
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LocalConnectionString %>"
            ProviderName="<%$ ConnectionStrings:LocalConnectionString.ProviderName %>" 
            UpdateCommand="UPDATE [UserData] SET [ClientName]=@ClientName, [UserName]=@UserName, [Password]=@Password, [eMail]=@eMail, [ClientAddress]=@ClientAddress, [Comments]=@Comments WHERE [ID]=@ID"
            >
            <%--
           DeleteCommand="DELETE FROM UserData WHERE ID=@ID"
            --%>
           
            <InsertParameters>
                <asp:Parameter Name="Client_txtbox1" Type="String" Size="255" />
                <asp:Parameter Name="User_txtbox1" Type="String" Size="255" />
                <asp:Parameter Name="Password_txtbox1" Type="String" Size="255" />
                <asp:Parameter Name="email_txtbox1" Type="String" Size="300" />
                 <asp:Parameter Name="ClientAddress_txtbox1" Type="String" Size="255" />
                 <asp:Parameter Name="comments_txtbox1" Type="String" Size="255" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="ID" Type="Int32" />
                <asp:Parameter Name="ClientName" Type="String" Size="255" />
                <asp:Parameter Name="UserName" Type="String" Size="255" />
                <asp:Parameter Name="Password" Type="String" Size="255" />
                <asp:Parameter Name="eMail" Type="String"  Size="300" />
                <asp:Parameter Name="ClientAddress" Type="String" Size="255" />
                <asp:Parameter Name="Comments" Type="String" Size="255" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <br />
        <br />
        <br />
    </div>
</asp:Content>
